package net.cyndeline.builders.common

import net.cyndeline.builders.MapBuilder
import net.cyndeline.GameMap.LevelMap
import com.escalatesoft.subcut.inject.BindingModule
import com.escalatesoft.subcut.inject.Injectable
import net.cyndeline.UUIDFactory
import net.cyndeline.UUIDProvider
import net.cyndeline.GameMap.Grid
import net.cyndeline.GameMap.dataStructure.MapGrid
import net.cyndeline.GameMap.dataStructure.GridBasedMap
import net.cyndeline.GameMap.Tile

class SquareGridBuilder(implicit val bindingModule: BindingModule) extends MapBuilder with Injectable {
  
  def build(width: Int, height: Int, name: String): LevelMap = {
    
    /* Create pieces of the map that is needed for assembly. */
    val id = (injectOptional[UUIDFactory] getOrElse new UUIDProvider()).random
    val grid = injectOptional[Grid] getOrElse new MapGrid()
    val map = injectOptional[LevelMap] getOrElse new GridBasedMap()
    
    /* Set the data. */
    grid.build(width, height)
    map.build(id, grid, name)
    map
  }
}